<?php
/**
 * @file: Followm.php
 * @User: shiwuhao
 * @Date: 16/4/11 19:24
 * @synopsis: 关注关系model
 */

class Followm extends CI_Model
{
    public function __construct()
    {
        parent::__construct();
    }

    /**
     * @param int $user_id   关注人ID
     * @param int $follow_id 被关注人ID
     * @return int 关注状态 0 未关注 1 已关注 3 互粉
     */
    public function follow($user_id = 0, $follow_id = 0)
    {
        if(empty($user_id) || empty($follow_id))
        {
            return 0;
        }
        $followKey = FOLLOW_PREFIX.$user_id;
        $fansKey   = FANS_PREFIX.$follow_id;
        $addtime   = time();

        $res1 = $this->redis->zAdd($followKey, $addtime,  $follow_id);
        $res2 = $this->redis->zAdd($fansKey, $addtime, $user_id);

        if ($res1 && $res2) {
            $filter = array('following' => $user_id, 'followers' => $follow_id);
            $total  = $this->db->where($filter)->count_all_results('ml_member_relation');
            if (!$total && $follow_id) {  // $follow_id 可能为空
                $data = array('following' => $user_id, 'followers' => $follow_id, 'addtime' => $addtime);
                $this->db->insert('ml_member_relation', $data);
                //新加粉丝给一分
                $this->load->model('newjfpointsm');
                // $related_id 为  保证 日志表里 $follow_id.'-'.$user_id  重新想个办法
                $result = $this->newjfpointsm->add_jfpoints_for_one_user($follow_id,DAILY_ADD_FAN,$follow_id,DAILY_ADD_FAN);
                if($result['code'] == 0){
                    //发消息  给了积分才能发消息
                    $user_info = $this->userm->getUserInfoById($follow_id);
                    $jfpoints_content = $this->newjfpointsm->get_jfpoints_content(DAILY_ADD_FAN);
                    $send_content = array("post_first_img"=>'http://static.medical-lighter.com/share/images/jfpoints.jpg',"content"=>$jfpoints_content['stage']);
                    $send_content = json_encode($send_content);
                    $this->messagem->send_msg_basic(31495, $follow_id, $send_content,$apptype=2,$msgtype=3);//默认用轻盈医学官方账号发送
                }

                //写入用户行为日志
                $event_log_array = array(
                    'action'      => 'add_follow',
                    'action_type' => 4,
                    'type'        => 1,
                    'uid1'        => $user_id,
                    'uid2'        => $follow_id,
                    'post_id'     => '',
                    'comment_id'  => '',
                    'addtime'     => $addtime
                );
                $this->load->model("usereventlogm");
                $this->usereventlogm->insert_user_event_log($event_log_array);
            }

        } else {

            $params    = array('user_id' => $user_id, 'follow_id' => $follow_id, 'addtime' => $addtime, 'res1' => $res1, 'res2' => $res2);
            w_log('redis_follow_fail:res1:'.json_encode($params));
        }

        return $this->get_follow_status($user_id, $follow_id);
    }

    /**
     * 取消关注
     * @param int $user_id   关注人ID
     * @param int $follow_id 被关注人ID
     * @return int 关注状态 0 未关注 1 已关注 3 互粉
     */
    public function unfollow($user_id = 0, $follow_id = 0)
    {
        $followKey = FOLLOW_PREFIX.$user_id;
        $fansKey   = FANS_PREFIX.$follow_id;

        $res1 = $this->redis->zRem($followKey, $follow_id);
        $res2 = $this->redis->zRem($fansKey, $user_id);

        if ($res1 && $res2) {
            $filter = array('following' => $user_id, 'followers' => $follow_id);
            $total  = $this->db->where($filter)->count_all_results('ml_member_relation');
            if ($total) {
                $this->db->where($filter)->delete("ml_member_relation");
            }

            //掉粉扣一分
            $this->load->model('newjfpointsm');
            // $related_id 为  保证 日志表里 $follow_id.'-'.$user_id  重新想个办法
            $result = $this->newjfpointsm->minus_jfpoints_for_one_user($follow_id,DAILY_ADD_FAN,$follow_id,DAILY_ADD_FAN);
            if($result['code'] == 0){
                //发消息  给了积分才能发消息
                $user_info = $this->userm->getUserInfoById($follow_id);
                $jfpoints_content = $this->newjfpointsm->get_jfpoints_content(DAILY_ADD_FAN);
                $send_content = array("post_first_img"=>'http://static.medical-lighter.com/share/images/jfpoints.jpg',"content"=>$jfpoints_content['stage'].'被取消');
                $send_content = json_encode($send_content);
                $this->messagem->send_msg_basic(31495, $follow_id, $send_content,$apptype=2,$msgtype=3);//默认用轻盈医学官方账号发送
            }

        } else {

            $params    = array('user_id' => $user_id, 'follow_id' => $follow_id, 'time' => time(), 'res1' => $res1, 'res2' => $res2);
            w_log('redis_unfollow_fail:res1:'.json_encode($params));

            return false;
        }

        return true;
    }

    /**
     * 判断是否是关注关系  A 是否关注 B
     * @param $user_id
     * @param $follow_id
     * @return bool
     */
    public function is_follow($user_id, $follow_id)
    {
        $followKey = FOLLOW_PREFIX.$user_id;
        $res = $this->redis->zRank($followKey, $follow_id);

        if ($res === false) return false;
        return true;
    }

    /**
     * 判断是否是粉丝关系 B 是否是 A 的粉丝
     * @param $user_id
     * @param $fans_id
     * @return bool
     */
    public function is_fans($user_id, $fans_id)
    {
        $fansKey = FANS_PREFIX.$user_id;
        $res = $this->redis->zRank($fansKey, $fans_id);

        if ($res === false) return false;
        return true;
    }

    /**
     * 判断两个人是否是互粉关系
     * @param $user_id
     * @param $follow_id
     * @return bool
     */
    public function is_mutual($user_id, $follow_id)
    {
        return $this->is_follow($user_id, $follow_id) && $this->is_follow($follow_id, $user_id);
    }

    /**
     * 获取两个人的关注关系
     * @param $user_id          当前用户ID
     * @param $target_user_id   目标用户ID
     * @return int              0 无关系 1 关注 3 互粉
     */
    public function get_follow_status($user_id, $target_user_id)
    {
        if ($this->is_mutual($user_id, $target_user_id)) {
            $status = 3;
        } elseif ($this->is_follow($user_id, $target_user_id)) {
            $status = 1;
        } else {
            $status = 0;
        }
        return $status;
    }

    /**
     * 获取用户关注数量
     * @param int $user_id
     * @return mixed
     */
    public function follow_count($user_id = 0)
    {
        $followKey = FOLLOW_PREFIX.$user_id;
        return $this->redis->zCard($followKey);
    }

    /**
     * 获取用户粉丝数量
     * @param int $user_id
     * @return mixed
     */
    public function fans_count($user_id = 0)
    {
        $fansKey = FANS_PREFIX.$user_id;
        return $this->redis->zCard($fansKey);
    }

    /**
     * 获取某个用户所有的粉丝IDS
     * @param int $user_id
     * @return mixed
     */
    public function get_fans_ids($user_id = 0)
    {
        $fansKey = FANS_PREFIX.$user_id;
        return $this->redis->zRevRange($fansKey, 0, -1);
    }

    /**
     * 获取某个用户所有的关注IDS
     * @param int $user_id
     * @return mixed
     */
    public function get_follow_ids($user_id = 0)
    {
        $followKey = FOLLOW_PREFIX.$user_id;
        return $this->redis->zRevRange($followKey, 0, -1);
    }

    /**
     * 获取互粉IDS
     * @param int $user_id
     * @return mixed
     */
    public function get_mutual_ids($user_id = 0, $withscore = false)
    {
        $fansKey   = FANS_PREFIX.$user_id;
        $followKey = FOLLOW_PREFIX.$user_id;
        $fofakey   = FOFA_PREFIX.$user_id;

        $this->redis->delete($fofakey);
        $this->redis->zInter($fofakey, array($fansKey, $followKey),NULL, 'MAX');
        $this->redis->expire($fofakey, 100);
        return $this->redis->zRevRange($fofakey, 0, -1, $withscore);
    }

    /**
     * 获取 与某个用户有关系的相关集合
     * @param $userId           当前登录用户ID
     * @param $targetUserId     目标用户ID
     * @param $findType         关注 or 粉丝  （follow or fans）
     * @param $page             当前页数
     * @param $perPage          分页条数
     * @return array
     */
    public function get_chunk_set($userId, $targetUserId, $findType, $page, $perPage)
    {
        $fansKey   = FANS_PREFIX.$userId;                           // 我的粉丝key
        $followKey = FOLLOW_PREFIX.$userId;                         // 我的关注key
        $findKey   = FIND_PREFIX.$userId;                           //

        $targetKey = $findType.':'.$targetUserId;                   // 待查询目标key
        $fofaKey   = FIND_INTER_FOFA_PREFIX.$userId;                // 互粉集合key

        $findInterFollowKey = FIND_INTER_FOLLOW_PREFIX.$userId;     // 要查询的集合与我的关注交集key
        $findInterFansKey   = FIND_INTER_FANS_PREFIX.$userId;       // 要查询的集合与我的粉丝交集key

        $start = ($page - 1) * $perPage;
        $end   = $start + $perPage - 1; //这里是从0开始的  所以需要再-1
        $findSet = $this->redis->zRevRange($targetKey, $start, $end, TRUE);

        $findInterFollowSet = array(); // 要查询的集合与我的关注交集
        $findInterFansSet   = array(); // 要查询的集合与我的粉丝交集

        // 清除临时key
        $this->redis->delete($findKey);
        $this->redis->delete($fofaKey);
        $this->redis->delete($findInterFansKey);
        $this->redis->delete($findInterFollowKey);

        foreach($findSet as $uid => $score) {
            $this->redis->zAdd($findKey, $score, $uid);
        }

        if ($userId == $targetUserId) { // 看自己
            if ($findType == 'fans') { // 要查询的集合与我的关注交集
                $this->redis->zInter($fofaKey, array($findKey, $followKey));
            } else if ($findType == 'follow') { // 要查询的集合与我的粉丝交集
                $this->redis->zInter($fofaKey, array($findKey, $fansKey));
            }

        } else { // 看别人

            $this->redis->zInter($fofaKey, array($findKey, $fansKey, $followKey));  // 要查询的集合与我的互粉交集
            $this->redis->zInter($findInterFansKey, array($findKey, $fansKey));     // 要查询的集合与我的粉丝交集
            $this->redis->zInter($findInterFollowKey, array($findKey, $followKey)); // 要查询的集合与我的关注交集

            $findInterFansSet   = $this->redis->zRevRange($findInterFansKey, 0, -1);
            $findInterFollowSet = $this->redis->zRevRange($findInterFollowKey, 0, -1);
        }

        $fofaset = $this->redis->zRevRange($fofaKey, 0, -1);

        $this->redis->expire($findKey, 100);
        $this->redis->expire($fofaKey, 100);
        $this->redis->expire($findInterFansKey, 100);
        $this->redis->expire($findInterFollowKey, 100);

        return array(
            'findSet' => $findSet,
            'fofaSet' => $fofaset,
            'findInterFollowSet' => $findInterFollowSet,
            'findInterFansSet'   => $findInterFansSet
        );
    }


    public function get_chunk_expert_set($userId, $targetUserId, $findType)
    {
        $fansKey = FANS_PREFIX . $userId;                           // 我的粉丝key
        $followKey = FOLLOW_PREFIX . $userId;                         // 我的关注key
        $findKey = FIND_PREFIX . $userId;                           //

        $targetKey = $findType . ':' . $targetUserId;                   // 待查询目标key
        $fofaKey = FIND_INTER_FOFA_PREFIX . $userId;                // 互粉集合key

        $findInterFollowKey = FIND_INTER_FOLLOW_PREFIX . $userId;     // 要查询的集合与我的关注交集key
        $findInterFansKey = FIND_INTER_FANS_PREFIX . $userId;       // 要查询的集合与我的粉丝交集key

        $findSet = $this->redis->zRevRange($targetKey, 0, -1, TRUE);

        $findInterFollowSet = array(); // 要查询的集合与我的关注交集
        $findInterFansSet = array(); // 要查询的集合与我的粉丝交集

        // 清除临时key
        $this->redis->delete($findKey);
        $this->redis->delete($fofaKey);
        $this->redis->delete($findInterFansKey);
        $this->redis->delete($findInterFollowKey);

        foreach ($findSet as $uid => $score) {
            $this->redis->zAdd($findKey, $score, $uid);
        }

        if ($userId == $targetUserId) { // 看自己
            if ($findType == 'fans') { // 看自己的粉丝列表
                $this->redis->zInter($fofaKey, array($findKey, $followKey));
            } else if ($findType == 'follow') { // 看自己的关注列表
                $this->redis->zInter($fofaKey, array($findKey, $fansKey));
            }

        } else { // 看别人

            $this->redis->zInter($fofaKey, array($findKey, $fansKey, $followKey));  // 要查询的集合与我的互粉交集
            $this->redis->zInter($findInterFansKey, array($findKey, $fansKey));     // 要查询的集合与我的粉丝交集
            $this->redis->zInter($findInterFollowKey, array($findKey, $followKey)); // 要查询的集合与我的关注交集

            $findInterFansSet = $this->redis->zRevRange($findInterFansKey, 0, -1);
            $findInterFollowSet = $this->redis->zRevRange($findInterFollowKey, 0, -1);
        }

        $fofaset = $this->redis->zRevRange($fofaKey, 0, -1);

        $this->redis->expire($findKey, 100);
        $this->redis->expire($fofaKey, 100);
        $this->redis->expire($findInterFansKey, 100);
        $this->redis->expire($findInterFollowKey, 100);

        return array(
            'findSet' => $findSet,
            'fofaSet' => $fofaset,
            'findInterFollowSet' => $findInterFollowSet,
            'findInterFansSet' => $findInterFansSet
        );
    }

    /**
     * 获取用户 粉丝 关注 列表
     * @param $isSelf               是否是自己   (1 or 0)
     * @param $findType             关注 or 粉丝 (follow or fans)
     * @param $findSet              array
     * @param $fofaSet              array
     * @param $findInterFollowSet   array
     * @param $findInterFansSet     array
     * @return array
     */
    public function get_user_list($isSelf, $findType, $findSet, $fofaSet, $findInterFollowSet, $findInterFansSet, $myUserId)
    {
        if (!$findSet) return array();

        ci_load_once('userm');
        ci_load_once('threadm');

        $key = USER_INFO_PREFIX.$myUserId;
        $lastSeeFansTime = (int)$this->redis->hGet($key, 'pre_time_fans');
        $lastSeeFansTime = $lastSeeFansTime ? $lastSeeFansTime : time();

        $userList = array();
        foreach ($findSet as $userId => $score) {
            if (!$userId) continue;

            $userInfo = $this->userm->getUserInfo($userId);
            if (!$userInfo)   // 这里如果用户不存在 需要清除掉 缓存内容
            {
                $cache_key = $findType == 'follow' ? FOLLOW_PREFIX . $userId : FANS_PREFIX . $userId;
                $this->redis->zRem($cache_key, $userId);
                continue;
            }

            if (in_array($userId, $fofaSet)) {
                $following_status = 3; // 互粉
            } else {
                if ($isSelf) { // 看自己
                    $following_status = $findType == 'follow' ? 1 : 0;
                } else { // 看别人
                    if (in_array($userId, $findInterFansSet)) {
                        $following_status = 0; // 粉丝 （状态标识为未关注）
                    } else if (in_array($userId, $findInterFollowSet)) {
                        $following_status = 1; // 关注
                    } else {
                        $following_status = 0;
                    }
                }
            }

            $is_expert = $userInfo["user_level"] ? 1 : 0;
            $tmp_user_info = array();
            $tmp_user_info['truename']          = $is_expert == 1 ? $userInfo['truename'] : '';
            $tmp_user_info['username']          = $userInfo['username'];
            $tmp_user_info['specialty']         = $this->threadm->get_thread_name($userInfo['thread']);
            $tmp_user_info['addtime']           = $userInfo["add_time"];
            $tmp_user_info['followers']         = $userId;
            $tmp_user_info['is_expert']         = $is_expert;
            $tmp_user_info['user_level']        = $userInfo['user_level'];
            $tmp_user_info['head_ico']          = $userInfo['head_ico'];
            $tmp_user_info['practice_hospital'] = $userInfo['practice_hospital'];
            $tmp_user_info['post_title']        = $userInfo['post_title'];
            $tmp_user_info['expert_info']       = $userInfo['expert_info'];
            $tmp_user_info['verified_status']   = $userInfo['verified_status'];
            $tmp_user_info['admin_level']       = $userInfo['admin_level'];
            $tmp_user_info['following_status']  = $following_status;
            $tmp_user_info['is_new']            = (($findType == 'fans') && ($score > $lastSeeFansTime)) ? 1 : 0;

            $userList[] = $tmp_user_info;
        }

        return $userList;
    }


    /**
     * 获取用户 粉丝 关注 列表
     * @param $isSelf               是否是自己   (1 or 0)
     * @param $findType             关注 or 粉丝 (follow or fans)
     * @param $findSet              array
     * @param $fofaSet              array
     * @param $findInterFollowSet   array
     * @param $findInterFansSet     array
     * @return array
     */
    public function get_user_expert_list($isSelf, $findType, $findSet, $fofaSet, $findInterFollowSet, $findInterFansSet, $myUserId)
    {
        if (!$findSet) return array();

        $this->load->model('userm');
        $this->load->model('specialtym');

        $key = USER_INFO_PREFIX . $myUserId;
        $lastSeeFansTime = (int)$this->redis->hGet($key, 'pre_time_fans');
        $lastSeeFansTime = $lastSeeFansTime ? $lastSeeFansTime : time();

        $userList = array();
        foreach ($findSet as $userId => $score) {
            if (!$userId) continue;

            $userInfo = $this->userm->getUserInfo($userId);
            if (!$userInfo || !$userInfo['user_level']) continue;

            if (in_array($userId, $fofaSet)) {
                $following_status = 3; // 互粉
            } else {
                if ($isSelf) { // 看自己
                    $following_status = $findType == 'follow' ? 1 : 0;
                } else { // 看别人
                    if (in_array($userId, $findInterFansSet)) {
                        $following_status = 0; // 粉丝 （状态标识为未关注）
                    } else if (in_array($userId, $findInterFollowSet)) {
                        $following_status = 1; // 关注
                    } else {
                        $following_status = 0;
                    }
                }
            }

            // 2.3 版本 统一格式（我的所有专家格式一致）
            $special_info = $this->db->select('goodat as expert_info,is_service,fee,consult_count')->from('ml_specialist')->where('user_id', $userId)->get()->row_array();
            $is_expert = $userInfo["user_level"] ? 1 : 0;
            $tmp_user_info = array();
            $tmp_user_info['id'] = $userId;
            $tmp_user_info['is_service'] = $special_info['is_service'] ? $special_info['is_service'] : '';
            $tmp_user_info['consult_count'] = $special_info['is_service'] ? $special_info['consult_count'] : 0;
            $tmp_user_info['fee'] = $special_info['fee'] ? $special_info['fee'] : '';
            $tmp_user_info['truename'] = $is_expert == 1 ? $userInfo['truename'] : '';
            $tmp_user_info['username'] = $userInfo['username'];
            $tmp_user_info['specialty'] = $this->specialtym->get_thread_info_by_id($userInfo['thread']);
            $tmp_user_info['addtime'] = $userInfo["add_time"];
            $tmp_user_info['followers'] = $userId;
            $tmp_user_info['is_expert'] = $is_expert;
            $tmp_user_info['user_level'] = $userInfo['user_level'];
            $tmp_user_info['thread_name'] = $this->threadm->get_thread_name($userInfo['thread']);
            $tmp_user_info['head_ico'] = $userInfo['head_ico'];
            $tmp_user_info['practice_hospital'] = $userInfo['practice_hospital'];
            $tmp_user_info['post_title'] = $userInfo['post_title'];

            $tmp_user_info['expert_info'] = $special_info['expert_info'] ? $special_info['expert_info'] : '';

            $tmp_user_info['verified_status'] = $userInfo['verified_status'];
            $tmp_user_info['admin_level'] = $userInfo['admin_level'];
            $tmp_user_info['following_status'] = $following_status;
            $tmp_user_info['is_new'] = (($findType == 'fans') && ($score > $lastSeeFansTime)) ? 1 : 0;

            $userList[] = $tmp_user_info;
        }

        return $userList;
    }



    /**
     * 更新用户最后一次看 烦死列表的时间
     * @param $user_id
     * @return mixed
     */
    public function update_my_status($user_id)
    {
        $key = USER_INFO_PREFIX.$user_id;
        $res = $this->redis->hSet($key, 'pre_time_fans', time());
        if (!$res) {
            w_log('update_my_status_fail:'.$user_id);
        }
        return $res;
    }


    /**
     * 更新用户最后一次看 好友列表的时间
     * @param $user_id
     * @return mixed
     */
    public function update_my_friend_status($user_id)
    {
        $key = USER_INFO_PREFIX.$user_id;
        $res = $this->redis->hSet($key, 'pre_time_friend', time());
        if (!$res) {
            w_log('update_my_friend_status_fail:'.$user_id);
        }
        return $res;
    }






    /**
     * 获取我的好友
     * @param int $user_id  我的user_id
     * @param int $observer_id 观察者
     * @return array
     */
    public function get_frined_list($user_id, $observer_id = 0)
    {
        $findSet = $this->get_mutual_ids($user_id,TRUE);

        if (!$findSet) return array();

        ci_load_once('userm');
        ci_load_once('threadm');

        # 上次查看好友列表时间
        $key = USER_INFO_PREFIX.$user_id;
        $lastSeeFansTime = (int)$this->redis->hGet($key, 'pre_time_frined');
        $lastSeeFansTime = $lastSeeFansTime ? $lastSeeFansTime : time();
        # 新加的好友数目
        $num_new = 0;

        $uids = array_keys($findSet);
        $user_info_dict = $this->userm->getUserInfoByIDsForShow($uids, $observer_id);
        foreach ($user_info_dict as $uid => &$userinfo) {
            $userinfo["is_my_friend"] = 1;
            $userinfo["specialty"] = $this->threadm->get_thread_name($userinfo['thread']);
            $userinfo["addtime"] = '';
            $userinfo["followers"] = $uid;
            $userinfo["share_desc"] = $userinfo['username'] . ' ' . $userinfo['practice_hospital'] . ' ' . $userinfo['specialty'];

            if (! isset($findSet[$uid])) {
                continue;
            }
            $itm = $findSet[$uid];

            if ($lastSeeFansTime && intval($lastSeeFansTime) <= intval($itm)) {
                // 上次查看列表之后确定好友关系的
                $userinfo["is_new"] = 1;
                $num_new += 1;
            }
            else {
                $userinfo["is_new"] = 0;
            }
        }
        $userList = array_values($user_info_dict);

        return array("follow_list"=>$userList,"count"=>count($findSet), "num_new"=>$num_new);
    }


    /**
     * 获取某个用户的关注关系
     * @param $user_id int
     * @return array [ $uid => $relationship, ... ]
     */
    public function getUserRelationship($user_id)
    {
        if (!$user_id) {
            return null;
        }

        $fans = $this->get_fans_ids($user_id);
        $follows = $this->get_follow_ids($user_id);

        $relationship = array();
        foreach ($fans as $uid) {
            if (!$uid) {
                continue;
            }
            $relationship[$uid] = 0;    // 粉丝
        }

        foreach ($follows as $uid) {
            if (!$uid) {
                continue;
            }
            if (!isset($relationship[$uid])) {
                $relationship[$uid] = 1;    // 关注
            }
            else {
                $relationship[$uid] = 3;    // 互粉
            }
        }

        return $relationship;
    }

    public function search_my_fans_by_name($userId,$search_content)
    {
        ci_load_once('userm');
        ci_load_once('threadm');
        $where = array('a.followers'=>$userId,'b.username like'=>"%".$search_content."%");
        $list = $this->db->select('b.id')
            ->from('ml_member_relation as a')
            ->join('ml_fellow as b','a.following = b.id','left')
            ->where($where)
            ->get()->result_array();

        $userList = [];
        foreach ($list as $val)
        {
            $userInfo = $this->userm->getUserInfo($val['id']);

            $following_status = $this->get_follow_status($userId, $val['id']);

            $is_expert = $userInfo["user_level"] ? 1 : 0;
            $tmp_user_info = array();
            $tmp_user_info['truename']          = $is_expert == 1 ? $userInfo['truename'] : '';
            $tmp_user_info['username']          = $userInfo['username'];
            $tmp_user_info['specialty']         = $this->threadm->get_thread_name($userInfo['thread']);
            $tmp_user_info['addtime']           = $userInfo["add_time"];
            $tmp_user_info['followers']         = $val['id'];
            $tmp_user_info['is_expert']         = $is_expert;
            $tmp_user_info['user_level']        = $userInfo['user_level'];
            $tmp_user_info['head_ico']          = $userInfo['head_ico'];
            $tmp_user_info['practice_hospital'] = $userInfo['practice_hospital'];
            $tmp_user_info['post_title']        = $userInfo['post_title'];
            $tmp_user_info['expert_info']       = $userInfo['expert_info'];
            $tmp_user_info['verified_status']   = $userInfo['verified_status'];
            $tmp_user_info['admin_level']       = $userInfo['admin_level'];
            $tmp_user_info['following_status']  = $following_status;
            $tmp_user_info['is_new']            = 0;

            $userList[] = $tmp_user_info;
        }


        
        
        
        return $userList;
    }
}